package com.wjj.sixinone.controller.admin;

import com.wjj.sixinone.common.enums.ApiTypeConst;
import com.wjj.sixinone.common.pojo.vo.UserFormVO;
import com.wjj.sixinone.common.pojo.vo.UserVO;
import com.wjj.sixinone.common.util.Result;
import com.wjj.sixinone.service.FaceAiService;
import com.wjj.sixinone.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(ApiTypeConst.API_ADMIN+"/user")

public class AdminController {
    @Resource
    private FaceAiService faceAiService;
    @Resource
    private final UserService service;
    public AdminController(UserService service) {
        this.service = service;
    }
    @GetMapping("/selectUserByLimit")
    public Result selectUserByLimit(UserVO userVO){
        return service.selectUserByLimit(userVO);
    }
    @PostMapping("/deleteById")
    public Result deleteById(@RequestBody Map<String,Integer> map){

        return service.removeUserById(map.get("id")) ;
    }
    @PostMapping("/updateById")
    public Result updateById(@RequestBody UserFormVO userVO){
        return service.updateUserById(userVO);
    }
    @PostMapping("/addUser")
    public Result addUser(@RequestBody UserFormVO userVO){
        return service.addUser(userVO);
    }
    @GetMapping("uploadExcel")
    public void uploadExcel(HttpServletResponse response){
         service.uploadExcel( response);
    }
    @PostMapping("/logout")
    public Result logout(HttpServletRequest request){
        return service.logout( request);
    }

    @RequestMapping("/registerFace")
    @ResponseBody
    public Result registerFace(@RequestBody Map<String,String> map) {
        String imageBase64 = map.get("imageBase64");
        StringBuffer imageBase64Buf =  new StringBuffer(imageBase64);
        return faceAiService.registerFace(imageBase64Buf);
    }
    @PostMapping("/checkFace")
    public Result checkFace(@RequestBody Map<String,String> map){
        String imgBase64 = map.get("imgBase64");
        StringBuffer imageBase64BF = new StringBuffer(imgBase64);
        return faceAiService.checkFace(imageBase64BF);
    }

}
